package cn.iocoder.yudao.module.famous.doctor.controller.app.forumRecord;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.famous.doctor.controller.admin.forumRecord.vo.*;
import cn.iocoder.yudao.module.famous.doctor.convert.forumRecord.FamForumRecordConvert;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.forumRecord.FamForumRecordDO;
import cn.iocoder.yudao.module.famous.doctor.service.forumRecord.FamForumRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 点赞/收藏--记录表")
@RestController
@RequestMapping("/famous.doctor/fam-forum-record")
@Validated
public class AppFamForumRecordController {

    @Resource
    private FamForumRecordService famForumRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建点赞/收藏--记录表")
    public CommonResult<Long> createFamForumRecord(@Valid @RequestBody FamForumRecordCreateReqVO createReqVO) {
        return success(famForumRecordService.createFamForumRecord(createReqVO));
    }

    @PostMapping("/createRedis")
    @Operation(summary = "Redis点赞/收藏--记录表")
    public CommonResult<Long> createRedis(@Valid @RequestBody FamForumRecordCreateReqVO createReqVO) {
        return success(famForumRecordService.createRedis(createReqVO));
    }

    @GetMapping("/getMyRedis")
    @Operation(summary = "我的收藏/点赞")
    public CommonResult<List<FamForumRecordDO>> getMyRedis(@RequestParam("mystate") Long mystate) {
        return success(famForumRecordService.getMyRedis(mystate));
    }

    @PutMapping("/updateMyRedis")
    @Operation(summary = "我的收藏")
    public CommonResult<Boolean> updateMyRedis(@RequestParam("mystate") @Valid @RequestBody FamForumRecordUpdateReqVO updateReqVO) {
        famForumRecordService.updateMyRedis(updateReqVO);
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新点赞/收藏--记录表")
    public CommonResult<Boolean> updateFamForumRecord(@Valid @RequestBody FamForumRecordUpdateReqVO updateReqVO) {
        famForumRecordService.updateFamForumRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除点赞/收藏--记录表")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteFamForumRecord(@RequestParam("id") Long id) {
        famForumRecordService.deleteFamForumRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得点赞/收藏--记录表")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<FamForumRecordRespVO> getFamForumRecord(@RequestParam("id") Long id) {
        FamForumRecordDO famForumRecord = famForumRecordService.getFamForumRecord(id);
        return success(FamForumRecordConvert.INSTANCE.convert(famForumRecord));
    }

    @GetMapping("/list")
    @Operation(summary = "获得点赞/收藏--记录表列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<FamForumRecordRespVO>> getFamForumRecordList(@RequestParam("ids") Collection<Long> ids) {
        List<FamForumRecordDO> list = famForumRecordService.getFamForumRecordList(ids);
        return success(FamForumRecordConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得点赞/收藏--记录表分页")
    public CommonResult<PageResult<FamForumRecordRespVO>> getFamForumRecordPage(@Valid FamForumRecordPageReqVO pageVO) {
        PageResult<FamForumRecordDO> pageResult = famForumRecordService.getFamForumRecordPage(pageVO);
        return success(FamForumRecordConvert.INSTANCE.convertPage(pageResult));
    }
}
